--
-- Author: shunguo.chen
-- Date: 2018-01-10 20:14:59
--
-- CosplayRole 角色扮演的角色

local Skill = require("app.public.dao.Skill")
local UserBaseInfo = require("app.public.dao.UserBaseInfo")

local fileName = string.getModeName(...)
local ClassRef = class(fileName)

function ClassRef:ctor(data)
    if data then
        self:init(data)
    end
end

-- data = conf
function ClassRef:init(data) 
	self._data = data

	self.id = tonumber(data.ID)

	self._chooseUid = nil

	-- avatar params
	local params = {
		name = L(data.name),
		classID = tonumber(data.classID),
		raceID = tonumber(data.raceID),
		gender = tonumber(data.gender),
		hairID = tonumber(data.hairID),
		faceID = tonumber(data.faceID),
		hairColorID = tonumber(data.hairColor),
		fashionIDs = {}
	}
	self._baseInfo = UserBaseInfo.new(params)

	self._enemyRaceID = tonumber(data.raceID1)

	self._duty = L(data.dutyShow)
	self._desc = L(data.desShow)
	self._roleSimpleDesc = L(data.roleSimpleDesc)   --角色定位文案
end

function ClassRef:getAvatarParams(isEnemy)
	if isEnemy then
		local baseInfo = self._baseInfo:clone()
		baseInfo.raceID = self._enemyRaceID
		return baseInfo
	else
		return self._baseInfo
	end
end

-- 惰性处理，普攻不算在内
function ClassRef:getSkills()
	if not self._skills then
		local data = self._data
		local skills = {}
		for i=2,5 do
			local id = data["classSkill" .. i]
			if id then
				local skill = Skill.new()
				skill:read({uid=id})
				skills[#skills + 1] = skill
			else
				break
			end
		end
		self._skills = skills
	end
	return self._skills
end

-- 角色属性
function ClassRef:getAttrs()
	if not self._attrs then
		local conf = GD:queryCosplayPropConf(self._data.propPool)
		local dict = conf:getValues()
		self._attrs = UD:calAttrByKey(dict, 1)
	end
	return self._attrs
end

-- 简单tipData
function ClassRef:getTipData()
	return {name=self._baseInfo.name, duty=self._duty}
end

function ClassRef:getName()
	return self._baseInfo.name
end

function ClassRef:getDuty()
	return self._duty
end

function ClassRef:getDesc()
	return self._desc
end

function ClassRef:isChoose()
	return self._chooseUid ~= nil
end

function ClassRef:isMyChoose()
	return self._chooseUid == UD:getUid()
end

function ClassRef:setChooseUid(uid)
	self._chooseUid = uid
end

function ClassRef:getChooseUid()
	return self._chooseUid
end

return ClassRef